<?php

include 'functions.php';
if (isset($_POST['ids']) && is_array($_POST['ids']) && isset($_POST['Bname'])) {
    $x = $_POST['ids'];
    implode(",", $x);
    if ($_POST['Bname'] == "mark") {
        foreach ($x as $item) {
            $id = intval($item);
            $r = mysql_query("SELECT seen FROM messages WHERE message_id = $id") or die(mysql_error());
            while ($row = mysql_fetch_assoc($r)) {
                if ($row['seen'] == "1") {
                    mysql_query("UPDATE messages SET seen = '0' WHERE message_id = $id") or die(mysql_error());
                } else if ($row['seen'] == "0") {
                    mysql_query("UPDATE messages SET seen = '1' WHERE message_id = $id") or die(mysql_error());
                }
            }
        }
    } else if ($_POST['Bname'] == "deleteSelected") {
        foreach ($x as $item) {
            $id = intval($item);
            mysql_query("DELETE FROM member_message_member WHERE message_id = {$id}") or die(mysql_error());
        }
    }else {
        echo "no buttons";
    }
} else {
    echo 'mfish';
}
?>
